<?php
session_start();

require 'phpmailer2/PHPMailerAutoload.php';



$mail = new PHPMailer;
$mail->CharSet = 'UTF-8';
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'wirobrajan.idwebhost.com';  // Specify main and backup server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'admin@natawebs.com';                            // SMTP username
$mail->Password = 'admin';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted

$mail->From = 'admin@natawebs.com';
$mail->FromName = 'KIDS WEBSITE (ICT 2)';

$mail->addAddress('');               // Name is optional
//$mail->addReplyTo('hendranatas@yahoo.com', 'Information');
$mail->addCC('');
$mail->addBCC('');

$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML



if($_POST[target]=='contact_us')
{
$mail->addAddress('hendranatas@yahoo.com', '');  // Add a recipient
$mail->Subject = 'Someone from KIDS WEBSITE has sent a message to you (Contact US)';

$_SESSION[cu_name]=$_POST[name];
$_SESSION[cu_email]=$_POST[email];
$_SESSION[cu_phone]=$_POST[phone];
$_SESSION[cu_message]=$_POST[message];

ob_start();
include ('email-template/contact_us.php');
$body = ob_get_clean();
$mail->Body = $body;

}else if($_POST[target]=='contact_us_dev')
{
$mail->addAddress('hendranatas@yahoo.com', '');  // Add a recipient
$mail->Subject = 'Developer Interested in your KIDS Website';
$_SESSION[cu_name]=$_POST[name];
$_SESSION[cu_email]=$_POST[email];
$_SESSION[cu_phone]=$_POST[phone];
$_SESSION[cu_message]=$_POST[message];

ob_start();
include ('email-template/contact_us.php');
$body = ob_get_clean();
$mail->Body = $body;
if (isset($_FILES['uploaded_file']) &&
    $_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK) {
    $mail->AddAttachment($_FILES['uploaded_file']['tmp_name'],
                         $_FILES['uploaded_file']['name']);
}
}
else if($_GET[target]=='registration')
{
$mail->addAddress($_GET[email], '');  // Add a recipient
$mail->Subject = 'Your Account has been registered and needs activation(KIDS WEBSITE)';
ob_start();
include ('email-template/registration.php');
$body = ob_get_clean();
$mail->Body = $body;

}else if($_GET[target]=='forgot_pass')
{
$mail->addAddress($_GET[email], '');  // Add a recipient
$mail->Subject = 'Your Password has been reset (KIDS WEBSITE)';
$_SESSION[username]=$_GET[username];
ob_start();
include ('email-template/reset_password.php');
$body = ob_get_clean();

$mail->Body = $body;

}else	//when account has been activated
{
$mail->addAddress($_GET[email], '');  // Add a recipient
$mail->Subject = 'Your Account Has been Activated (KIDS WEBSITE)';
$_SESSION[user_id]=$_GET[user_id];
ob_start();
include ('email-template/congratulation.php');
$body = ob_get_clean();

$mail->Body = $body;



}

if(!$mail->send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

if($_GET[target]=='forgot_pass')
{
header('Location: index.php?email=sent');
}
else if($_GET[target]=='registration')
{
header('Location: index.php?email=registration');
}elseif($_POST[target]=='contact_us')
{
header('Location: index.php?email=sent');
}else
{
header('Location: index.php?account=activated&#page_three');

}









